package com.example.design.proxy.dynamic;

import java.lang.reflect.Proxy;

/**
 * @Description 动态代理测试类
 * @ClassName DynamicProxyTest
 * @Author Yumuhui
 * @Date 2020/5/14 1:04
 * @Version 1.0.0
 */
public class DynamicProxyTest {

    public static void main(String[] args) {
        Subject realSubject = new RealSubject();

//        DynamicProxy proxy = new DynamicProxy(realSubject);
//        ClassLoader classLoader = realSubject.getClass().getClassLoader();
//        Subject subject = (Subject) Proxy.newProxyInstance(classLoader, new  Class[]{Subject.class}, proxy);

        Subject subject = (Subject) Proxy.newProxyInstance(Subject.class.getClassLoader(),
                new Class[]{Subject.class}, new DynamicProxy(realSubject));

        subject.operation();
    }
}
